package one.four.twentyEight;

public class StackUsingQueue<Item> {
	Queue<Item> q;

	public StackUsingQueue() {
		q = new Queue<Item>();
	}

	public void push(Item item) {
		q.enqueue(item);
	}

	public Item pop() {
		for (int i = 0; i < q.size() - 1; i++) {
			q.enqueue(q.dequeue());
		}
		return q.dequeue();
	}

	public static void main(String[] args) {
		StackUsingQueue<String> s = new StackUsingQueue<String>();
		s.push("a");
		s.push("b");
		s.push("c");
		System.out.println(s.pop());
		System.out.println(s.pop());
		
		s.push("d");
		s.push("e");
		s.push("f");
		System.out.println(s.pop());
		
	}

}
